﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Restbucks.Shared.Domain;
using Restbucks.Shared.Representations;
using Restbucks.Shared.Mappers;
using System.Xml.Serialization;
using System.IO;
using Restbucks.Server;

namespace Restbucks.Client
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Order order = new Order(Location.InStore, new Item[] { 
                new Item(Drink.Cappuccino, Shared.Domain.Size.Large, Milk.Semi) });

            OrderRepresentation orderRep = OrderRepresentationMapper.GetRepresentation(order);

            // Create a new XmlSerializer instance with the type of the test class
            XmlSerializer SerializerObj = new XmlSerializer(typeof(OrderRepresentation));

            if (true)
            {
                using (StreamWriter sw = new StreamWriter("order1.xml"))
                {

                    // Create a new file stream to write the serialized object to a file
                    //StringWriter sw = new StringWriter();
                    SerializerObj.Serialize(sw, orderRep);

                }
            }
            //else
            //{
            //    // Create a new file stream to write the serialized object to a file
            //    StringWriter sw = new StringWriter();
            //    SerializerObj.Serialize(sw, orderRep);

            //    // Cleanup
            //    sw.Close();
            //    //textBox1.Clear();
            //    //textBox1.AppendText(sw.ToString());
            //}
        }

        private void listBoxOrders_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void button1_Click_1(object sender, RoutedEventArgs e)
        {
            RefreshOrders();
        }


        private void RefreshOrders()
        {
            OrderRepresentation[] orders = RestbucksClient.GetOrders();
        }

        private void buttonCreateOrder_Click(object sender, RoutedEventArgs e)
        {
            RestbucksClient.debugCreateOrder();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Debug.RaiseLogEvent += new EventHandler<DebugEventArgs>(Debug_RaiseLogEvent);
        }

        void Debug_RaiseLogEvent(object sender, DebugEventArgs e)
        {
            textboxDebug.AppendText(e.Message);
        }
    }
}
